package com.xiyue.leaspring.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.xiyue.leaspring.dao.IDeptDao;
import com.xiyue.leaspring.po.Dept;

@Repository
public class DeptDaoImpl implements IDeptDao {

	
	@PersistenceContext//获得EntityManager(配置文件只配置了EntityManagerFactory)
	private EntityManager entityManager;//JPA操作对象
	
	@Transactional
	@Override
	public boolean doCreate(Dept vo) {
		boolean flag =  this.entityManager.merge(vo)!=null;
		return flag;
	}

	@Override
	public List<Dept> findAll() {
		String jpql = "select d from Dept as d";
		TypedQuery<Dept>query = this.entityManager.createQuery(jpql,Dept.class);
		return query.getResultList();
	}

}
